// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
// import store from './store';
import ElementUI from 'element-ui';
import axios from '@/assets/js/axios';
import store from './store';
import moment from 'moment';
import '@/assets/css/reset.css';
import 'element-ui/lib/theme-chalk/index.css';
import * as filters from '@/assets/js/filters';
import '../static/font/iconfont.css';
import '@/assets/js/jsonExportCsv';
// import vueMiniPlayer from 'vue-mini-player';
import publicComponents from './components';

import echarts from 'echarts'; //引入echarts
Vue.prototype.$echarts = echarts; //引入组件
Vue.prototype.$bus = new Vue();
Vue.prototype.$moment = moment;

Vue.config.productionTip = false;
Vue.use(publicComponents);
Vue.use(ElementUI);
Vue.use(axios);
// Vue.use(vueMiniPlayer);
Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key]);
});

// 进行权限处理
router.beforeEach((to, from, next) => {
    if (to.meta.authList) {
        store.dispatch('CHECK_AUTH', to.meta.authList).then(res => {
            to.meta.authResult = res;
            // console.log(res, to.meta.authList.auth_page);
            if (!to.meta.authList.auth_page || res.auth_page) {
                next();
            }else {
                // 没有页面访问权限,直接阻止
                router.push({
                    path: '/no-auth'
                });
                return;
            }
        }).catch(res => {
            console.warn('无授权列表,重新拉取');
            router.push({
                path: '/',
                query: {
                    TO: escape(JSON.stringify({name: to.name, path: to.path, query: to.query, params: to.params}))
                }
            });
        });
    } else {
        next();
    }
});

/* eslint-disable no-new */
var vue = new Vue({
    el: '#app',
    router,
    store,
    components: {
        App
    },
    template: '<App/>'
});
